package br.com.fc.service.io;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.util.zip.DeflaterOutputStream;
import java.util.zip.InflaterInputStream;


public class ServiceObject {
	
	
	public void write(Object object, OutputStream outputStream) throws IOException {
		DeflaterOutputStream deflaterOutputStream = new DeflaterOutputStream(outputStream);
		ObjectOutputStream objectOutputStream = new ObjectOutputStream(deflaterOutputStream);
		objectOutputStream.writeObject(object);
		objectOutputStream.flush();
		deflaterOutputStream.close();
		objectOutputStream.close();
	}
	
	public Object read(InputStream inputStream) throws IOException, ClassNotFoundException {
		InflaterInputStream inflaterInputStream = new InflaterInputStream(inputStream);
		ObjectInputStream objectInputStream = new ObjectInputStream(inflaterInputStream); 
		try {
			return objectInputStream.readObject();		
		} finally {
			inflaterInputStream.close();
			objectInputStream.close();
		}
	}

}
